package cn.stylefeng.guns.modular.gridsystem.timer;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.guns.core.context.constant.ConstantContextHolder;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import java.io.File;
import java.util.List;

/**
 * 删除引擎eval文件
 *
 * @author ytx
 * @date 2023/05/23
 */
@Configuration
@EnableScheduling
public class DeleteEngineEvalFileTime {

    //每周一0点执行
    @Scheduled(cron = "0 0 0 ? * MON")
//    @Scheduled(cron = "0 0 */1 * * ?")
    @Async
    public void deleteEngineEvalTask(){
        String enginePath = ConstantContextHolder.getEngineDeletePath();
        File engineEvalFile = new File(enginePath);
        if (engineEvalFile.exists()){
            List<File> engineEvalDirectory = FileUtil.loopFiles(engineEvalFile,1,File::isDirectory);
            for (File directoryFile : engineEvalDirectory){
                String directoryName = directoryFile.getName();
                if (!StrUtil.isNumeric(directoryName)){
                    FileUtil.del(directoryFile);
                }
            }
        }
    }
}
